package com.itheima.controller;

import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.ShearCaptcha;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.itheima.manager.SoulManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import java.io.IOException;
import java.util.Map;

@RestController
public class SoulController {

    @Autowired
    SoulManager soulManager;

    /**
     * 登录功能
     * @return
     */
    @PostMapping("/soul/login")
    public ResponseEntity login(@RequestBody Map<String,String> map){

        String username = map.get("username");
        String password = map.get("password");
        String code = map.get("code");


        return soulManager.login(username,password,code);
    }

    /**
     * 验证码
     * @return
     */
    @GetMapping("/soul/sendCode")
    public void sendCode(String username, HttpServletResponse response) throws IOException {

        ShearCaptcha lineCaptcha = soulManager.sendCode(username);


        //response.setContentType("image/jpeg");
        lineCaptcha.write(response.getOutputStream());

    }






}
